﻿using Abp.EntityFramework;
using Laboratory.Entities.User;
using Laboratory.EntityFramework;
using Laboratory.EntityFramework.Repositories;
using Laboratory.IRepositories.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Laboratory.Repositories.User
{
    public class RoleRepository : LaboratoryRepositoryBase<Role, Guid>, IRoleRepository
    {
        public RoleRepository(IDbContextProvider<LaboratoryDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }



        /// <summary>
        /// 验证名称是否存在
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="name">名称</param>
        /// <returns></returns>
        public bool ExistsName(Guid? id, string name)
        {
            Expression<Func<Role, bool>> condition =
                x => (id == null || x.Id != id) &&
                x.Name == name;

            Role role = this.FirstOrDefault(condition);

            return role != null;
        }

    }
}
